home *** CD-ROM | disk | FTP | other *** search
- /*****
- * CQTApp.c
- *
- * Application methods for a QuickTime demo application.
- *
- * Copyright © 1992 Joe Zobkiw. All rights reserved.
- * Portions Copyright © 1990 Symantec Corporation. All rights reserved.
- *
- *****/
-
- #include "CQTApp.h"
- #include "CQTDoc.h"
- #include "Commands.h"
- #include "Defines.h"
- #include "CEBSwitchboard.h"
- #include "CEBCollaborator.h"
- #include "QuickTime Utilities.h"
- #include <TBUtilities.h>
- #include <TCLUtilities.h>
- #include <Global.h>
- #include <GestaltEqu.h>
- #include <Movies.h>
-
- extern OSType gSignature;
- extern long gQuickTimeVersion;
- extern CEBCollaborator *gEBCollaborator;
-
- #define kExtraMasters 4
- #define kRainyDayFund 20480
- #define kCriticalBalance 20480
- #define kToolboxBalance 20480
-
- /***
- * IQTApp
- *
- * Initialize the application. Your initialization method should
- * at least call the inherited method. If your application class
- * defines its own instance variables or global variables, this
- * is a good place to initialize them.
- *
- ***/
-
- void CQTApp::IQTApp(void)
-
- {
- OSErr err = noErr;
-
- CApplication::IApplication( kExtraMasters, kRainyDayFund,
- kCriticalBalance, kToolboxBalance);
-
- if (QuickTimeIsInstalled(&gQuickTimeVersion) == true) {
- FailOSErr(EnterMovies());
- } else {
- gQuickTimeVersion = 0;
- FailOSErr(gestaltUndefSelectorErr);
- }
-
- gEBCollaborator = new(CEBCollaborator);
- gEBCollaborator->IEBCollaborator();
- }
-
-
- /******************************************************************************
- MakeSwitchboard
-
- Create application's switchboard. We use a special "Event Broadcasting"
- Switchboard that will use our gEBCollaborator instance to broadcast events
- to any available Movie Controllers before handling them itself.
-
- This is how Movie Controllers get thier events.
-
- ******************************************************************************/
-
- void CQTApp::MakeSwitchboard( void)
- {
- itsSwitchboard = new(CEBSwitchboard);
- ((CEBSwitchboard*)itsSwitchboard)->IEBSwitchboard();
- }
-
- /***
- * SetUpFileParameters
- *
- * In this routine, you specify the kinds of files your
- * application opens.
- *
- *
- ***/
-
- void CQTApp::SetUpFileParameters(void)
-
- {
- inherited::SetUpFileParameters(); /* Be sure to call the default method */
-
- /**
- ** sfNumTypes is the number of file types
- ** your application knows about.
- ** sfFileTypes[] is an array of file types.
- ** You can define up to 4 file types in
- ** sfFileTypes[].
- **
- **/
-
- sfNumTypes = 1;
- sfFileTypes[0] = kApplicationFileType; // in CQTDoc.h
-
- /**
- ** Although it's not an instance variable,
- ** this method is a good place to set the
- ** gSignature global variable. Set this global
- ** to your application's signature. You'll use it
- ** to create a file (see CFile::CreateNew()).
- **
- **/
-
- gSignature = kApplicationSignature; // in CQTApp.h
- }
-
-
- /***
- * SetUpMenus
- *
- * Set up menus which must be created at run time, such as a
- * Font menu. You can eliminate this method if your application
- * does not have any such menus.
- *
- ***/
-
- void CQTApp::SetUpMenus()
- {
-
- inherited::SetUpMenus(); /* Superclass takes care of adding
- menus specified in a MBAR id = 1
- resource
- */
-
- /* Add your code for creating run-time menus here */
- }
-
-
-
- /***
- * DoCommand
- *
- * Your application will probably handle its own commands.
- * Remember, the command numbers from 1-1023 are reserved.
- * The file Commands.h contains all the predefined TCL
- * commands.
- *
- * Be sure to call the default method, so you can get
- * the default behvior for standard commands.
- *
- ***/
- void CQTApp::DoCommand(long theCommand)
-
- {
- switch (theCommand) {
-
- /* Your commands go here */
- case cmdAbout:
- Alert(kAboutALRT, nil);
- break;
-
- //
- // show standard movie preview open dialog. if the user selects a movie,
- // then we pass the FSSpec to OpenQTDocument which will handle opening
- // one of this application’s documents.
- //
-
- case cmdOpen: {
- FSSpec spec;
- if (GetMovieFileFSSpec(&spec)) {
- OpenQTDocument(&spec);
- }
- }
- break;
-
- default: inherited::DoCommand(theCommand);
- break;
- }
- }
-
-
- /***
- *
- * UpdateMenus
- *
- * Perform menu management tasks
- *
- ***/
-
- void CQTApp::UpdateMenus()
- {
- inherited::UpdateMenus(); /* Enable standard commands */
-
- /* Enable the commands handled by your Application class */
- }
-
-
- /***
- * Exit
- *
- * Chances are you won't need this method.
- * This is the last chance your application gets to clean up
- * things like temporary files before terminating.
- *
- ***/
-
- void CQTApp::Exit()
-
- {
- if (gQuickTimeVersion != 0)
- ExitMovies(); // tell QuickTime we are through
-
- if (gEBCollaborator != NULL)
- gEBCollaborator->Dispose(); // nuke our global CEBCollaborator
- }
-
-
- /***
- * CreateDocument
- *
- * The user chose New from the File menu.
- * In this method, you need to create a document and send it
- * a NewFile() message.
- *
- ***/
-
- void CQTApp::CreateDocument()
-
- {
- CQTDoc *theDocument = NULL;
-
- TRY
- {
- theDocument = new(CQTDoc);
- theDocument->IQTDoc(this, TRUE);
- theDocument->NewFile();
- }
-
- CATCH
- {
- //if (theDocument) theDocument->Dispose();
- ForgetObject(theDocument);
- }
- ENDTRY;
- }
-
- /***
- * OpenDocument
- *
- * Converts the TCL’s SFReply into an FSSpec and then calls OpenQTDocument to
- * open the movie document. This is only used when a movie is double-clicked
- * from the Finder or an odoc AppleEvent is sent.
- *
- ***/
-
- void CQTApp::OpenDocument(SFReply *macReply)
- {
- FSSpec spec;
-
- FailOSErr(FSMakeFSSpec(macReply->vRefNum, 0L, macReply->fName, &spec));
- this->OpenQTDocument(&spec);
- }
-
- /***
- * OpenQTDocument
- *
- * Open a document using the FSSpec provided. In this case, it will be spec to a
- * Movie document.
- *
- ***/
-
- void CQTApp::OpenQTDocument(FSSpec *spec)
- {
- CQTDoc *theDocument = NULL;
-
- TRY
- {
- theDocument = new(CQTDoc);
- theDocument->IQTDoc(this, TRUE);
- theDocument->OpenQTFile(spec);
- }
- CATCH
- {
- ForgetObject(theDocument);
- }
- ENDTRY;
- }
-